package com.itheima.excel;

import com.itheima.util.ExportExcel;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

public class Demo01 {
    public static void main(String[] args) throws Exception {
        HSSFWorkbook workbook = new HSSFWorkbook();                        // 创建工作簿对象
        String title = "翟老师登基大典演讲稿";
        for (int x=0;x<2;x++) {
            HSSFSheet sheet = workbook.createSheet(title+x);                     // 创建工作表
            HashMap<String, Object> dataMap = new HashMap<String, Object>();
            List<HashMap<String, Object>> listMap = new ArrayList<HashMap<String, Object>>();
            for (int i = 0; i < 30; i++) {
                dataMap.put("datetime"+i, new Date());
                dataMap.put("person"+i, "翟老师"+i);
                dataMap.put("type"+i, "文本");
                dataMap.put("content"+i, "今天朕登基！今天朕登基！今天朕登基！今天朕登基！今天朕登基！今天朕登基！");
                listMap.add(dataMap);
            }

            String[] rowsName = new String[]{"序号", "时间", "发言人", "类型", "消息"};
            List<Object[]> dataList = new ArrayList<Object[]>();
            Object[] objs = null;
            for (int i = 0; i < listMap.size(); i++) {
                HashMap<String, Object> data = listMap.get(i);
                objs = new Object[rowsName.length];
                objs[0] = i;
                objs[1] = data.get("datetime"+i);
                objs[2] = data.get("person"+i);
                objs[3] = data.get("type"+i);
                objs[4] = data.get("content"+i);
                dataList.add(objs);
            }

            ExportExcel ex = new ExportExcel(title, rowsName, dataList);
            ex.export(workbook,sheet,x);
        }
    }

    public static void main2(String[] args) throws Exception {
        HSSFWorkbook workbook = new HSSFWorkbook();
        String title = "翟老师登基大典演讲稿";
        HSSFSheet sheet = workbook.createSheet(title);// 创建工作簿对象
        String[] rowsName = new String[]{"序号", "时间", "发言人", "类型", "消息" };
        // 创建工作表
        List<Object[]> dataList = new ArrayList<Object[]>();
        for (int i = 0; i < 10; i++) {
            Object[] objects = new Object[5];
            objects[0] = i;
            objects[1] = "2021-9-" + i;
            objects[2] = "zhaichaojie";
            objects[3] = "牛逼";
            objects[4] = "咱也不知道";
            dataList.add(objects);
        }

        ExportExcel ex = new ExportExcel(title, rowsName, dataList);
        ex.export(workbook, sheet, 0);
    }
}
